const express = require('express')
const cors = require('cors')
const fs = require('fs')
const app = express()
app.use(cors({
    credentials: true,
    optionsSuccessStatus: 200,
    origin: 'http://127.0.0.1:5500',
}))
//http://127.0.0.1:3000/user
app.get('/user', (request, response) => {
    const user = { name1: 'beidou', age: 18 }
    fs.readFile('./xiaobei.webp', (err, data) => {
        if (err) {
            response.sendStatus(400)
        } else {
            user.avatar = data.toString('base64')
            response.send(user)
        }
    })
})
app.listen(3000, function () {
    console.log('serve start at http://127.0.0.1:3000')
})